home *** CD-ROM | disk | FTP | other *** search
- /* cat > headers/error.h << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* error.h: header for error.c file */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- #define error_h 1
-
- #include "all.h"
- #include "newext.h"
-
- /* EOF */
- /* cat > src+obj/error/msg2_stderr.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* msg2_stderr: two-line error message on stderr. */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "error.h" */
-
- void msg2_stderr (s1, s2) char *s1, *s2;
- {
-
- fprintf (stderr, "%s\n%s\n%s\n%s\n",
- " ----- ERROR MESSAGE -----",
- s1, s2,
- " ----- ERROR MESSAGE -----");
- return;
- }
- /* EOF */
-
- /* cat > error/msg_write.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* msg_write: write message to text subwindow. */
- /* Complete message handler is here. */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "error.h" */
-
- msg_write(msg)
- char *msg;
- {
- /* Implementation note(s):
- 1. On the first time through determine the message limit.
- 2. The message limit is a user specified default. The current range
- is [3, 100].
- 3. A rollaflex of messages is maintained for the user. It
- starts by saving all the messages up to the message limit
- each prepended by a message number of the form
- [msg %d] ->
- When the message limit is first succeeded a restart message
- is outputted followed by the new message starting at 1. The
- original message at the beginning numbered 1 is deleted. This
- cycles indefinitely.
- 4. If the message has a number of lines (each separated by a newline)
- each line is output as a new line in the window shifted over by
- the space taken up by the prepended message number. A newline
- is not required to terminate the message. If it is not there
- it is outputted by this function.
- 5. The window has been setup to wrap on a character.
- 6. The beginning of the last message is always (should be) visible in
- the window.
- 7. Currently at most 3 lines can be displayed in the text subwindow.
-
- Sun BUG: textsw_normalize_view () does not work properly. I cannot
- put the the first character of the last message at the TOP
- of the window. It is visible, but not much else.
- */
- int abs_msg_limit, i, j, value;
- char prefix[24]; /* include space for 12 digits */
- char prefix_blanks[24]; /* include space for 12 digits */
- char int_scratch1[13]; /* maximum of 12 digits */
- char int_scratch2[13]; /* maximum of 12 digist */
- char *p_defaultstr, *ptr, *msg_remain, *p_line;
- Textsw_index msgsw_ipoint, start, end;
-
- static int startup = 1;
- static int msg_num = 0;
- static int full = 0;
- static int len_prefix, msg_limit;
- static char *format = "[msg %d] "; /* maximum of 12 digits */
- static char *msg_txt = "[msg ]";
- static char *err_msg1_p1 = "Warning: No defaults message limit - ";
- static char *err_msg1_p2 = " used.\n";
- static char *err_msg2_p1 = "Warning: Bad defaults message limit - ";
- static char *err_msg2_p2 = " used.\n";
- static char *err_msg3_p1 = "Warning: Message limit not in range [3, ";
- static char *err_msg3_p2 = " ] - ";
- static char *err_msg3_p3 = " used.\n";
- static char *restart_msg = "~~~~~~~~~~ Restart Message Numbering ~~~~~~~~~~\n";
-
- msgsw_ipoint = (Textsw_index) window_get (msgsw,
- TEXTSW_INSERTION_POINT);
- if (msgsw_ipoint == 0) /* want to continue even though you ask
- to exit */
- {
- msg_num = 0;
- full = 0;
- }
- if (startup) /* first time through - setup */
- {
- startup = 0;
- if ((p_defaultstr = get_defaults (MESSAGE_LIMIT)) == NULL)
- {
- msg_limit = DEFAULT_MESSAGE_LIMIT;
- (void) sprintf (int_scratch1, "%d", msg_limit);
- len_prefix = strlen (msg_txt) + strlen (int_scratch1);
- sprintf (prefix, format, ++msg_num);
- (void) strcpy (prefix + len_prefix, " -> ");
- (void) textsw_insert (msgsw, prefix, strlen(prefix));
- (void) textsw_insert (msgsw, err_msg1_p1, strlen (err_msg1_p1));
- (void) textsw_insert (msgsw, int_scratch1, strlen (int_scratch1));
- (void) textsw_insert (msgsw, err_msg1_p2, strlen (err_msg1_p2));
- }
- else
- {
- abs_msg_limit = ABSOLUTE_MESSAGE_LIMIT;
- msg_limit = strtol (p_defaultstr, &ptr, 10);
- if (*ptr != NULL) /* bad integer */
- {
- msg_limit = DEFAULT_MESSAGE_LIMIT;
- (void) sprintf (int_scratch1, "%d", msg_limit);
- len_prefix = strlen (msg_txt) + strlen (int_scratch1);
- sprintf (prefix, format, ++msg_num);
- (void) strcpy (prefix + len_prefix, " -> ");
- (void) textsw_insert (msgsw, prefix, strlen(prefix));
- (void) textsw_insert (msgsw, err_msg2_p1, strlen (err_msg1_p1));
- (void) textsw_insert (msgsw, int_scratch1, strlen (int_scratch1));
- (void) textsw_insert (msgsw, err_msg2_p2, strlen (err_msg1_p2));
- }
- else if (msg_limit < 3 || msg_limit > abs_msg_limit) /* bad range */
- {
- msg_limit = DEFAULT_MESSAGE_LIMIT;
- (void) sprintf (int_scratch1, "%d", msg_limit);
- len_prefix = strlen (msg_txt) + strlen (int_scratch1);
- sprintf (prefix, format, ++msg_num);
- (void) strcpy (prefix + len_prefix, " -> ");
- (void) textsw_insert (msgsw, prefix, strlen(prefix));
- (void) textsw_insert (msgsw, err_msg3_p1, strlen (err_msg1_p1));
- (void) textsw_insert (msgsw, int_scratch1, strlen (int_scratch1));
- (void) textsw_insert (msgsw, err_msg3_p2, strlen (err_msg1_p2));
- (void) sprintf (int_scratch2, "%d", abs_msg_limit);
- (void) textsw_insert (msgsw, int_scratch2, strlen (int_scratch2));
- (void) textsw_insert (msgsw, err_msg3_p3, strlen (err_msg1_p2));
- }
- else
- {
- char tmp[MAXNAMELEN]; /* need space simply to get the length */
-
- strcpy (tmp, p_defaultstr);
- (void) strip_wspace (tmp);
- len_prefix = strlen (msg_txt) + strlen (tmp);
- }
- }
- }
- /* implement the circular list of messages */
- if (msg_num == msg_limit)
- {
- msg_num = 0;
- full = 1;
- (void) textsw_insert (msgsw, restart_msg, strlen(restart_msg));
- }
- if (full)
- {
- /* determine start of string to erase up to from
- the beginning */
- sprintf (prefix, format, (msg_num + 2) % msg_limit);
- (void) strcpy (prefix + len_prefix, " -> ");
- start = 0;
-
- /* 0 means forward search - should always succeed - returns the updated value of start and end */
- value = textsw_find_bytes (msgsw, &start, &end, prefix, strlen (prefix), 0);
-
- /* erase the message - must be able to write into it! */
- window_set (msgsw, TEXTSW_READ_ONLY, FALSE, 0);
- value = textsw_erase (msgsw, 0, start);
- window_set (msgsw, TEXTSW_READ_ONLY, TRUE, 0);
- }
-
- msgsw_ipoint = (Textsw_index) window_get (msgsw,
- TEXTSW_INSERTION_POINT);
- sprintf (prefix, format, ++msg_num);
- (void) strcpy (prefix + len_prefix, " -> ");
- /* loop for multiple lines (separated by newline) in the
- string */
- msg_remain = msg;
- for (i = 0; (p_line = strchr (msg_remain, '\n')) != NULL; i++)
- {
- *p_line = '\0';
- if (i == 0)
- (void) textsw_insert (msgsw, prefix, strlen(prefix));
- else if (i == 1)
- {
- for (j = 0; j < strlen(prefix); j++)
- prefix_blanks[j] = ' ';
- prefix_blanks[strlen(prefix)] = '\0';
- (void) textsw_insert (msgsw, prefix_blanks, strlen(prefix_blanks));
- }
- else
- (void) textsw_insert (msgsw, prefix_blanks, strlen(prefix_blanks));
- (void) textsw_insert (msgsw, msg_remain, strlen(msg_remain));
- (void) textsw_insert (msgsw, "\n", 1);
- msg_remain = p_line + 1;
- *p_line = '\n';
- }
- if (msg[strlen(msg)] != '\n') /* no terminating newline */
- {
- if (i == 0)
- (void) textsw_insert (msgsw, prefix, strlen(prefix));
- else if (i == 1)
- {
- for (j = 0; j < strlen(prefix); j++)
- prefix_blanks[j] = ' ';
- prefix_blanks[strlen(prefix)] = '\0';
- (void) textsw_insert (msgsw, prefix_blanks, strlen(prefix_blanks));
- }
- else
- (void) textsw_insert (msgsw, prefix_blanks, strlen(prefix_blanks));
- (void) textsw_insert (msgsw, msg_remain, strlen(msg_remain));
- (void) textsw_insert (msgsw, "\n", 1);
- }
-
- textsw_normalize_view (msgsw, msgsw_ipoint);
- return;
- }
- /* EOF */
-
-